package edu.friday.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class MyRedisCache {
    @Autowired
    private RedisTemplate redisTemplate;
    public <T> ValueOperations<String, T> setCacheObject(String key, T value) {
        ValueOperations<String, T> ops = redisTemplate.opsForValue();
        ops.set(key, value);
        return ops;
    }

    public <T> ValueOperations<String, T> setCacheObject(String key, T value, Integer seconds, TimeUnit timeUnit) {
        ValueOperations<String, T> ops = redisTemplate.opsForValue();
        ops.set(key, value, seconds, timeUnit);
        return ops;
    }

    public <T> T getCacheObject(String key) {
        ValueOperations<String, T> ops = redisTemplate.opsForValue();
        return ops.get(key);
    }


}

